package com.itheima.a02static;

public class ArrayUtil {
    //私有化构造方法:工具类,不让外界创建他的对象
    private ArrayUtil(){}

    //要定义为静态的,方便调用
    //返回整组数组的内容如：[1,2,3,4,5](带中括号)
    public static String printArr(int[] arr){
        StringBuilder sb = new StringBuilder();     //字符串的拼接StringBuilder
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            if(i == arr.length-1){
                sb.append(arr[i]);
            }else{
                sb.append(arr[i]).append(", ");
            }
        }
        sb.append("]");
        return sb.toString();   //变成字符串返回
    }

    public static double getAverage(double[] arr){
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
        }
        return sum / arr.length;
    }
}
